package org.jeecg.modules.online.cgreport.util;

import java.io.StringReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

import org.jeecg.modules.online.cgform.utils.CgformUtil;

import net.sf.jsqlparser.JSQLParserException;
import net.sf.jsqlparser.expression.Alias;
import net.sf.jsqlparser.expression.CaseExpression;
import net.sf.jsqlparser.expression.DateValue;
import net.sf.jsqlparser.expression.DoubleValue;
import net.sf.jsqlparser.expression.Expression;
import net.sf.jsqlparser.expression.Function;
import net.sf.jsqlparser.expression.LongValue;
import net.sf.jsqlparser.expression.StringValue;
import net.sf.jsqlparser.expression.TimeKeyExpression;
import net.sf.jsqlparser.parser.CCJSqlParserManager;
import net.sf.jsqlparser.schema.Column;
import net.sf.jsqlparser.statement.select.AllTableColumns;
import net.sf.jsqlparser.statement.select.PlainSelect;
import net.sf.jsqlparser.statement.select.Select;
import net.sf.jsqlparser.statement.select.SelectBody;
import net.sf.jsqlparser.statement.select.SelectExpressionItem;
import net.sf.jsqlparser.statement.select.SelectItem;
import net.sf.jsqlparser.statement.select.SetOperationList;

/* renamed from: org.jeecg.modules.online.cgreport.c.a */
/* loaded from: hibernate-re-3.7.1-RC.jar:org/jeecg/modules/online/cgreport/c/a.class */
public class CgReportSqlFiledParseUtils {
    /* renamed from: a */
    public static Map<String, Object> m103a(String str) {
        HashMap hashMap = new HashMap(5);
        Select select = null;
        try {
            select = (Select) new CCJSqlParserManager().parse(new StringReader(str));
        } catch (JSQLParserException e) {
            e.printStackTrace();
        }
        SelectBody selectBody = select.getSelectBody();
        new ArrayList();
        if (selectBody instanceof SetOperationList) {
        	SetOperationList setOperationList = (SetOperationList)selectBody;
            List selects = setOperationList.getSelects();
            for (int i = 0; i < selects.size(); i++) {
                m102a(hashMap, m101a((PlainSelect) selects.get(i)));
            }
        }
        if (selectBody instanceof PlainSelect) {
            m102a(hashMap, m101a((PlainSelect) selectBody));
        }
        return hashMap;
    }

    /* renamed from: a */
    private static void m102a(Map<String, Object> map, List<String> list) {
        for (String str : list) {
            if (!"*".equals(str)) {
                map.put(str, str);
            }
        }
    }

    /* renamed from: a */
    public static List<String> m101a(PlainSelect plainSelect) {
        String name;
        List<SelectItem> selectItems = plainSelect.getSelectItems();
        ArrayList arrayList = new ArrayList();
        if (selectItems != null) {
            for (SelectItem selectItem : selectItems) {
                if (selectItem instanceof SelectExpressionItem) {
                    SelectExpressionItem selectExpressionItem = (SelectExpressionItem) selectItem;
                    Alias alias = selectExpressionItem.getAlias();
                    Expression expression = selectExpressionItem.getExpression();
                    if (expression instanceof CaseExpression) {
                        name = alias.getName();
                    } else if ((expression instanceof LongValue) || (expression instanceof StringValue) || (expression instanceof DateValue) || (expression instanceof DoubleValue)) {
                        name = Objects.nonNull(alias.getName()) ? alias.getName() : expression.getASTNode().jjtGetValue().toString();
                    } else if (expression instanceof TimeKeyExpression) {
                        name = alias.getName();
                    } else if (alias != null) {
                        name = alias.getName();
                    } else {
                        Object jjtGetValue = expression.getASTNode().jjtGetValue();
                        if (jjtGetValue instanceof Column) {
                            name = ((Column) jjtGetValue).getColumnName();
                        } else if (jjtGetValue instanceof Function) {
                            name = jjtGetValue.toString();
                        } else {
                            name = String.valueOf(jjtGetValue).replace(CgformUtil.f231C, "").replace("\"", "").replace("`", "");
                        }
                    }
                    arrayList.add(name.replace(CgformUtil.f231C, "").replace("\"", "").replace("`", ""));
                } else if (selectItem instanceof AllTableColumns) {
                    arrayList.add(selectItem.toString());
                } else {
                    arrayList.add(selectItem.toString());
                }
            }
        }
        return arrayList;
    }
}
